package com.example.jeong.yuejian10.Model;


import com.example.jeong.yuejian10.Bean.AttentionBean;
import com.example.jeong.yuejian10.Bean.EnterMatchBean;
import com.example.jeong.yuejian10.Bean.IsAttentionBean;
import com.example.jeong.yuejian10.Bean.MatchBean;
import com.example.jeong.yuejian10.Listener.RetrofitListener;
import com.example.jeong.yuejian10.Service.MatchService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.jeong.yuejian10.constant.Constant.BASE_URL;


public class MatchModel {
    private Retrofit retrofit;
    public MatchModel(){
        //创建实例
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //比赛列表
    public void getMatchList(final RetrofitListener listener){
        MatchService matchService = retrofit.create(MatchService.class);
        Call call = matchService.getMatchList();
        Callback<List<MatchBean>> callback = new Callback<List<MatchBean>>() {
            @Override
            public void onResponse(Call<List<MatchBean>> call, Response<List<MatchBean>> response) {
                List<MatchBean> trainBeen = response.body();
                listener.onSuccess(trainBeen);
            }
            @Override
            public void onFailure(Call<List<MatchBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }

    //比赛详情
    public Call<MatchBean> getMatchDetail(int m_id) {
        MatchService matchService = retrofit.create(MatchService.class);
        return matchService.getDetail(m_id);
    }
    //报名比赛
    public Call<EnterMatchBean> addMatch(int u_id, int m_id) {
        MatchService matchService = retrofit.create(MatchService.class);
        return matchService.addMatch(u_id,m_id);
    }

    //判断是否关注
    public Call<IsAttentionBean> getIsCollected(int u_id, int select_id, String flag){
        MatchService matchService=retrofit.create(MatchService.class);
        return matchService.getIsCollected(u_id, select_id, flag);
    }

    //关注大师
    public Call<AttentionBean> userCollectMatch(int u_id, int m_id){
        MatchService matchService=retrofit.create(MatchService.class);
        return matchService.userCollectMatch(u_id,m_id);
    }

}

